﻿using System.Text;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AlertTools
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private System.Timers.Timer timer;
        public MainWindow()
        {
            InitializeComponent();
            InitializeTimer();
        }

        private void InitializeTimer()
        {
            // 初始化定时器
            timer = new System.Timers.Timer();
            timer.Interval = 60000; // 默认1分钟
            timer.Elapsed += OnTimedEvent;
        }

        private void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            // 显示提醒信息
            Application.Current.Dispatcher.Invoke(() =>
            {
                MessageBox.Show(txtMessage.Text, "提醒", MessageBoxButton.OK, MessageBoxImage.Information);
            });
        }

        private void BtnStart_Click(object sender, RoutedEventArgs e)
        {
            if (!int.TryParse(txtInterval.Text, out int interval) || interval <= 0)
            {
                MessageBox.Show("请输入有效的正整数作为时间间隔（以毫秒为单位）", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // 设置定时器的时间间隔并启动定时器
            timer.Interval = interval;
            timer.Start();
            MessageBox.Show("定时任务已启动", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
        }

        private void BtnStop_Click(object sender, RoutedEventArgs e)
        {
            timer.Stop();
            MessageBox.Show("定时任务已停止", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
        }
    }
}